<!--内容开始-->
<section class="content">
    <div class="search">
        <form class="form-inline" action="" data-pjax>
            <input type="hidden" name="cate" value="{$cateId}">
            <input type="text" class="form-control" name="title" placeholder="关键字" value="{$title}">
            <input class="btn btn-flat btn-primary" type="submit" value="搜索">
            <a class="btn btn-flat btn-primary m_10" href="{:url('index',['cate'=>$cateId])}">显示全部</a>
            <input class="btn btn-flat btn-warning m_10 select_del" type="button" value="批量删除">
            <input class="btn btn-flat btn-danger m_10 select_move" type="button" value="批量移动">
            <a class="btn btn-flat btn-success m_10 f_r" href='{:url('add',['cate'=>$cateId])}'><i
                class="fa fa-plus m-r-10"></i>添 加</a>
        </form>
    </div>
    <!--数据表开始-->
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <!-- /.box-header -->
                    <div class="box-body table-responsive no-padding">
                        <table class="table table-bordered table-hover">
                            <tr>
                                <th class="t_c"><input type="checkbox" id="check"></th>
                                <th class="t_c">编号</th>
                                <th class="t_c">标题</th>
                                <th class="t_c">所属栏目</th>
                                <th class="t_c">浏览量</th>
                                <th class="t_c">添加时间</th>
                                <th class="t_c">状态</th>
                                <th class="t_c">排序</th>
                                <th class="t_c">操作</th>
                            </tr>
                            {volist name='list' id='list' empty="$empty"}
                            <tr>
                                <td class="t_c"><input type="checkbox" name="key[]" value="{$list.id}"></td>
                                <td class="t_c">{$list.id}</td>
                                <td>{$list.image ? '<a href="'.$list.image.'" target="_blank"><i
                                        class="fa fa-fw fa-image js_show_img" data-image="'.$list.image.'"></i></a> ' :
                                    ''}<a href="{:url('edit',['cate'=>$cateId,'id'=>$list.id])}">{$list.title}</a></td>
                                <td class="t_c"><a href="{:url('index',['cate'=>$list.cate_id])}">{$list.catname}</a>
                                </td>
                                <td class="t_c">{$list.hits}</td>
                                <td class="t_c">{$list.create_time|date='Y-m-d H:i:s'}</td>
                                <td class="t_c">
                                    {if $list.status==1}
                                    <a class="state state_ok" data-id="{$list.id}"><i
                                            class="fa fa-fw fa-check-square"></i></a>
                                    {else}
                                    <a class="state state_no" data-id="{$list.id}"><i
                                            class="fa fa-fw fa-check-square"></i></a>
                                    {/if}
                                </td>
                                <th class="t_c"><input class="form-control input-sm w_40 m_auto changeSort" type="text"
                                                       value="{$list.sort}" data-id="{$list.id}"></th>
                                <td class="t_c">
                                    <a class="btn btn-flat btn-info btn-xs"
                                       href="{:url('edit',['cate'=>$cateId,'id'=>$list.id])}">
                                        <i class="fa fa-edit"></i> 编辑
                                    </a>
                                    <a class="btn btn-flat btn-warning btn-xs list_del" data-id="{$list.id}">
                                        <i class="fa fa-trash-o"></i> 删除
                                    </a>
                                </td>
                            </tr>
                            {/volist}
                        </table>
                    </div>
                    <!-- /.box-body -->
                    <div class="box-footer clearfix page">
                        {$page|raw}
                        <!---->
                        {$pageSize|raw}
                        <!---->
                    </div>
                </div>
                <!-- /.box -->
            </div>
        </div>
    </div>
    <!--数据表结束-->
</section>
<!--内容结束-->

<script>
    //排序
    $(".changeSort").blur(function () {
        var url = "{:url('sort')}";
        var id = $(this).data("id");
        var sort = $(this).val();
        changeSort(url, id, sort);
    })

    //删除
    $(".list_del").click(function () {
        var url = "{:url('del')}";
        var id = $(this).data("id");
        delOne(url, id)
    })

    //状态
    $(".state").click(function () {
        var url = "{:url('state')}";
        var id = $(this).data("id");
        changeState(url, id);
    })

    //批量删除
    $(".select_del").click(function () {
        var url = "{:url('selectDel')}";
        delSelect(url);
    })

    //批量移动
    $(".select_move").click(function () {
        var url = "{:url('selectMove')}";
        var id = $("input:checkbox[name='key[]']:checked").map(function (index, elem) {
            return $(elem).val();
        }).get().join(',');
        if (id == '') {
            swal('请先选择要移动的项目', '', 'error');
            return;
        }

        //
        swal({
            title: '批量移动',
            input: 'select',
            inputOptions: {
			{volist name="cate" id="cate"}
			'_{$cate.id}': '{$cate.lcatname}',//sweetalert当value为数字时按数字排序所以这里拼接了一个_用于防止打乱排序
			{/volist}
		  },
        inputPlaceholder: '请选择',
                showCancelButton
        :
        true,
                inputValidator
        :
        function (value) {
            return new Promise(function (resolve, reject) {
                if (value == '') {
                    reject('请先选择要移动的栏目');
                    return false;
                }
                value = value.replace('_', "");//还原sweetalert中的无用赋值
                //只可以转移文章到同模型的ID中
                $.post(url, {id: id, cate: {$cateId}, cate_id_move: value, check: true}, function (result) {
                    console.log(result);
                    if (result.error == 1) {
                        reject(result.msg);
                    } else {
                        swal(result.msg, '', 'success').then(function () {
                            //window.location.reload()
                            $.pjax.reload('.content-wrapper'); //pjax 重载
                        });
                    }
                });
            });
        }
    })
        //
    })

    //显示数量
    $(".page_size").change(function () {
        var page_size = $(this).val();
        var url = "{:url('index',['cate'=>$cateId,'title'=>$title,'page_size'=>'pagesize'])}";
        url = url.replace("pagesize", page_size);
        pjaxReplace(url);
    });
</script>
